#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QPainter>
#include <QTimer>
#include <QMessageBox>
#include "imgbutton.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->btnStart->setAnimationImgPath(":/res/startBtn.png");
    ui->btnCreateMap->setAnimationImgPath(":/res/editBtn.png");
    ui->btnAbout->setAnimationImgPath(":/res/aboutBtn.png");
    ui->btnExit->setAnimationImgPath(":/res/exitBtn.png");

    //初始化选关窗口
    chooseWindow = new ChooseLevelWindow;
    //初始化编辑迷宫地图窗口
    editWindow = new MapEditWindow;

    //监听编辑地图窗口的返回按钮点击事件
    connect(editWindow, &MapEditWindow::backBtnClicked, [=](){
       editWindow->hide();
       setGeometry(editWindow->geometry());
       this->show();
    });

    //监听选关窗口的返回按钮点击事件
    connect(chooseWindow, &ChooseLevelWindow::backBtnClicked, [=](){
       chooseWindow->hide();
       setGeometry(chooseWindow->geometry());
       this->show();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnStart_clicked()
{
    // 按钮弹跳效果
    ui->btnStart->jumpDown();
    ui->btnStart->jumpUp();
    // 0.3秒后打开选择关卡页面
    QTimer::singleShot(300, this, [=](){
        this->hide();
        chooseWindow->setGeometry(this->geometry());
        chooseWindow->show();
    });
}

void MainWindow::on_btnCreateMap_clicked()
{
    ui->btnCreateMap->jumpDown();
    ui->btnCreateMap->jumpUp();
    //0.3秒后打开地图制作页面
    QTimer::singleShot(300, this, [=](){
        this->hide();
        editWindow->setGeometry(this->geometry());
        editWindow->show();
    });
}

void MainWindow::on_btnAbout_clicked()
{
    ui->btnAbout->jumpDown();
    ui->btnAbout->jumpUp();

    QTimer::singleShot(300, this, [=](){
         QMessageBox::about(this, "关于迷宫大师",
            "Code by 利哥  2024-07\n"
            "Language: C++ with Qt\n"
            "微信公众号：利哥AI实例探险");
    });
}

void MainWindow::on_btnExit_clicked()
{
    ui->btnExit->jumpDown();
    ui->btnExit->jumpUp();
    QTimer::singleShot(300, this, [=](){
        this->close();
    });
}

